<?php
/**************************************
 *
 * @services Redis服务层-主要与redis交互
 *
 **************************************/
namespace app\common\services;

use think\Db;
use think\Model;
use Redis;
use think\Env;
use app\common\config;
use app\common\model\FollowModel;


class RedisServices
{
    //redis格式
    protected $redis;
    protected $config;
    protected $FollowModel;

    public function __construct()
    {
        $this->config = new config\RedisConfig();
        $redis = new Redis();
        $this->redis = $redis;
        $this->FollowModel = new FollowModel();
        $redis->connect($this->config->redis_host, $this->config->redis_port);
        $redis->auth($this->config->redis_passwd);
    }

    /**
     *  每日新增数据存入HASH表中
     */
    public function saveHash($data)
    {
        //数据HASH表名
        $name = $this->config->hashName.$data['user_id'].'_'.$data['create_time'].':';
        //数据HASH表名存队列中
        $hsName = $this->config->collHashName.$data['user_id'].':';
        //删除该条数据的历史数据
//        $this->redis->del($name);
        $allName = $this->redis->lRange($hsName, 0, -1);
        if (isset($allName[0]) && $allName[0] == 'nil') {
            $this->redis->del($hsName);
        }
        $this->redis->lPush($hsName, $name);
        $this->redis->expire($hsName, $this->config->cacheTime);
        foreach ($data as $key => $v) {
            //检测占位符是否存在,存在则删除占位符
            if ($this->redis->hExists($name, 'seat')) {
                $this->redis->hDel($name, 'seat');
                unset($data['seat']);
            }

            $this->redis->hSet($name, $key, $v);
            //将每日新增数据名字保存到列表中
            $this->redis->expireAt($name, time()+$this->config->cacheTime);
            //列表设置时间
        }
    }

    /**
     *  获取hash表中当日的值
     */
    public function getHash($data)
    {
        $data['create_time'] = !isset($data['create_time']) ? time() : $data['create_time'];
        $name = $this->config->hashName.$data['user_id'].'_'.$data['create_time'].':';
        if ($this->redis->exists($name)) {
            return $this->redis->hGetAll($name);
        } else {
            return false;
        }
    }

    /*
     *  设置List占位符
     */
    public function setList($data)
    {
        $hsName = $this->config->collHashName.$data['user_id'].':';
        $this->redis->lPush($hsName, $data['seat']);
    }

    /**
     *  获取用户所有数据
     */
    public function getAllInfo($user_id)
    {
        $hsName = $this->config->collHashName.$user_id.':';
        if (!$this->redis->exists($hsName)) {
            return false;
        }
        //获取所有HASH表名
        $allName = $this->redis->lRange($hsName, 0, -1);
        if (!$allName) {
            return false;
        }

        //如果队列存在占位符 则返回占位符
        if (isset($allName[0]) && $allName[0] == 'nil') {
            return $allName;
        }
        foreach ($allName as $v) {
            $msg[$v] = $this->redis->hGetAll($v);
        }
        //检测是否有过期的数据,过期则重新入队
        foreach ($msg as $k => $v) {
            if (empty($v)) {
                $again[] = $k;
            }
            if (isset($v['seat'])) {
                unset($msg[$k]);
            }
        }

        if (isset($again)) {
            //有过期数据标识
            $again['ident'] = 'again';
            return $again;
        } else {
            return $msg;
        }
    }

    //文章点赞
    public function setClick($data)
    {
        //文章点赞队列名
        $clickClickName = $this->config->clickListName.$data['id'];
        //用户头像队列
        $clickImgName = $this->config->clickImgListName.$data['id'];
        $clickUserImgName = $this->config->clickUserImgName.$data['user_id'];
        //点赞键名
        $clickName = $this->config->clickName.$data['id'];
        //用户名
        $clickUserName = $this->config->clickUserName.$data['id'].':'.$data['user_id'];
        //集合名
        $setName = $this->config->clickQuenName.$this->config->clickTime.":";
        //总集合
        $queueSetName = $this->config->clickTotalName;
        //标记用户点赞 or 取消点赞
        $clickSginUser = $this->config->clickSginUser.$data['id'].$data['user_id'].":";
        //用户点赞过的文章保存hash
        $userClickAtr = $this->config->userClickAtr.$data['user_id'];
        //点赞过的文章hash键名
        $userAtr = $this->config->userAtr.$data['id'];
        //保存点过赞的文章
        $clUserSave = $this->config->clUserSave;
        //所有键名
        $allName = $this->redis->lRange($clickClickName, 0, -1);
        $keyExists = $this->redis->exists($clickName);
        $SginUserExists = $this->redis->exists($clickSginUser);
        if (!$keyExists) {
            //获取现有数据,加入缓存
            $arr = Db::query("select `click` from article where id = ? LIMIT 1",[$data['id']]);
            $records = !$arr ? 1 : $arr[0]['click'] + 1;
            $this->redis->set($clickName, $records);
            //数据点赞名入列
            if (!in_array($clickName, $allName)) {
                $this->redis->lPush($clickClickName, $clickName);
            }
            //用户入列
            if (!in_array($clickUserName, $allName)) {
                $this->redis->lPush($clickClickName, $clickUserName);
            }
            //用户对该文章是否点赞标识
            $signUser = $this->sginUser($data);
            if ($signUser) {
                $this->redis->set($clickSginUser, $signUser['whether']);
            } else {
                $this->redis->set($clickSginUser, 1);
            }
            //保存用户点过赞的文章
//            $this->redis->hset($userClickAtr, $userAtr, $data['id']);
        } elseif($keyExists) {
            if (!$SginUserExists) {
                $this->redis->set($clickSginUser, -1);
            }
            //数据点赞名入列
            if (!in_array($clickName, $allName)) {
                $this->redis->lPush($clickClickName, $clickName);
            }
            //用户已取消点赞
            if (!in_array($clickUserName, $allName)) {
                $this->redis->lPush($clickClickName, $clickUserName);
            }
            $num = $this->redis->get($clickSginUser);
            //判断用户点赞(1) or 取消点赞(-1)
            if ($num == 1) {
                $this->redis->decr($clickName);
                $this->redis->set($clickSginUser, -1);
                $whether = $this->redis->get($clickSginUser);
                $clickNum = $this->redis->get($clickName);
                //取消点赞删除文章
//                $this->redis->hDel($userClickAtr, $userAtr);
                //删除保存的头像
                $this->redis->lRem($clickImgName, $clickUserImgName, 1);
                $this->redis->lRem($clickUserImgName, $data['img'], 1);
                $this->redis->hSet($clUserSave, $clickUserName , $whether);
                //点赞过的人头
                $userImg = $this->getClickImg($data['id']);
                return ['whether' => $whether, 'clickNum' => $clickNum, 'user_img' => $userImg];
            } elseif ($num == -1) {
                $init = $this->redis->get($clickName);
                if (!$init) {
                    $this->redis->set($clickName, 1);
                } else {
                    $this->redis->incr($clickName);
                }
                $this->redis->set($clickSginUser, 1);
            }//mtyw_click_user:24:3
        }
        //保存用户头像
        $this->redis->lPush($clickImgName, $clickUserImgName);
        $this->redis->lPush($clickUserImgName, $data['img']);

        $this->redis->expireAt($clickClickName, time()+$this->config->cacheTime);
        //保存信息加入集合
        $this->redis->sAdd($setName, $data['id']);
        //保存用户点过赞的文章
        $this->redis->hset($userClickAtr, $userAtr, $data['id']);
        $this->redis->sAdd($queueSetName, $setName);//保存集合信息
        $whether = $this->redis->get($clickSginUser);
        $clickNum = $this->redis->get($clickName);
        //保存点过赞的文章
        $this->redis->hSet($clUserSave, $clickUserName , $whether);
        //点赞过的人头
        $userImg = $this->getClickImg($data['id']);
//        print_r($userImg);exit();
        return ['whether' => $whether, 'clickNum' => $clickNum, 'user_img' => $userImg];
    }

    /**
     *  获取点赞量
     *  @param int $id 心情id
     */
    public function getClick($id)
    {
        $clickName = $this->config->clickName.$id;
        $clickNum = $this->redis->get($clickName);
        if (!$clickNum) {
            $click = Db::table('article')->field('click')->where('id', $id)->find();
            if ($click) {
                $clickNum = $click['click'];
                $this->redis->set($clickName, $clickNum);
            }
        }
        return $clickNum;
    }

    /**
     *  获取文章点赞的头像
     *  @param int $id 心情id
     */
    public function getClickImg($id)
    {
        //每一篇文章的最新三个点赞头像
        $clickImgName = $this->config->clickImgListName.$id;
        $data =  $this->redis->lRange($clickImgName, 0, 2);
        foreach($data as $v) {
            $msg =  $this->redis->lRange($v, 0, 2);
            $arr[] = $msg[0];
        }
        if (!$data) {
            return false;
        } else {
            return $arr;
        }
    }

    //判断用户是否已经点赞
    public function isClick($id, $userId)
    {
        $clickSginUser = $this->config->clickSginUser.$id.$userId.":";
        $SginUserExists = $this->redis->exists($clickSginUser);
        if ($SginUserExists) {
            $sgin = $this->redis->get($clickSginUser);
        } else {
            $data['id'] = $id;
            $data['user_id'] = $userId;
            $signUser = $this->sginUser($data);
            if ($signUser) {
                $sgin = $signUser['whether'];
            } else {
                $sgin = -1;
            }
        }
        return $sgin;
    }

    //获取用户对文章点赞标识
    public function sginUser($data)
    {
        $map['table_id'] = $data['id'];
        $map['user_id'] = $data['user_id'];
        $map['table'] = 'article';
        $map['status'] = 2;
        //用户对该文章是否点赞标识
        return  Db::table('click_follow')->field('whether')->where($map)->find();
    }

    //每日点赞、浏览数据入库
    public function everyClickRun()
    {
        $data = null;
        //点赞昨日集合名
        $queueSetName = $this->config->clickTotalName;
        $setName = $this->config->clickQuenName.date("Ymd", strtotime("-1 day")).":";
        $click = $this->redis->sMembers($setName);
        //浏览量集合名
        $queueViewName = $this->config->viewQuenJh;
        $viewQuenName = $this->config->viewQuenName.date("Ymd", strtotime("-1 day")).":";
        $view = $this->redis->sMembers($viewQuenName);
        if (!$click && !$view) {
            return 'null';
        }
        //点赞
        if ($click) {
            foreach ($click as $v) {
                $clickName = $this->config->clickName.$v;
                $click = $this->redis->get($clickName);
                $data = Db::table('article')->where('id', $v)->update(['click' => $click]);
            }
        }
        //浏览量
        if ($view) {
            foreach ($view as $v) {
                $viewName = $this->config->viewName.$v;
                $view = $this->redis->get($viewName);
                $data = Db::table('article')->where('id', $v)->update(['view' => $view]);
            }
        }
        //从集合信息列表删除本集合
        $this->redis->sRem($queueSetName, $setName);
        $this->redis->sRem($queueViewName, $viewQuenName);
        //删除集合
        $this->redis->delete($setName);
        $this->redis->delete($viewQuenName);
        if ($data) {
            return true;
        } else {
            return false;
        }
    }

    //每日关注量入库
    public function everyFollowRun()
    {
        $data = null;
        //浏览量集合名
        $queueSetName = $this->config->followTotalName;
        $setName = $this->config->followQuenName.date("Ymd", strtotime("-1 day")).":";
//        $setName = 'mtyw_follow_quen:20180425:';
        $follow = $this->redis->sMembers($setName);
        if (!$follow) {
            return 'null';
        }
        //浏览量
        foreach ($follow as $v) {
            $followName = $this->config->followName.$v;
            $view = $this->redis->get($followName);
            $data = Db::table('special')->where('id', $v)->update(['follow_num' => $view]);
        }
        //从集合信息列表删除本集合
        $this->redis->sRem($queueSetName, $setName);
        //删除集合
        $this->redis->delete($setName);
        if ($data) {
            return true;
        } else {
            return false;
        }
    }

    //专题关注
    public function setFollow($data)
    {
        //专题队列名
        $followClickName = $this->config->followListName.$data['id'];
        //用户头像队列
        $followImgName = $this->config->followImgListName.$data['id'];
        //点赞的用户头像键名
        $followUserImgName = $this->config->followUserImgName.$data['user_id'];
        //关注键名
        $followName = $this->config->followName.$data['id'];
        //用户名
        $followUserName = $this->config->followUserName.$data['id'].':'.$data['user_id'];
        //集合名
        $setName = $this->config->followQuenName.$this->config->clickTime.":";
        //总集合
        $queueSetName = $this->config->followTotalName;
        //标记用户关注 or 取消关注
        $followSginUser = $this->config->followSginUser.$data['id'].$data['user_id'].":";
        //用户关注过的专题保存hash
        $userFollowSp = $this->config->userFollowSp.$data['user_id'];
        //关注过的专题hash键名
        $followSper = $this->config->followSper.$data['id'];
        //保存关注过的文章
        $foUserSave = $this->config->foUserSave;
        //所有键名
        $allName = $this->redis->lRange($followClickName, 0, -1);
        $keyExists = $this->redis->exists($followName);
        $SginUserExists = $this->redis->exists($followSginUser);
        if (!$keyExists) {
            //获取现有数据,加入缓存
            $arr = Db::query("select `follow_num` from special where id = ? LIMIT 1",[$data['id']]);
            $records = $arr[0]['follow_num'] + 1;
            $this->redis->set($followName, $records);
            //数据关注入列
            if (!in_array($followName, $allName)) {
                $this->redis->lPush($followClickName, $followName);
            }
            //用户入列
            if (!in_array($followUserName, $allName)) {
                $this->redis->lPush($followClickName, $followUserName);
            }
            //用户对该文章是否关注标识
            $signUser = $this->sginUser($data);
            if ($signUser) {
                $this->redis->set($followSginUser, $signUser['whether']);
            } else {
                $this->redis->set($followSginUser, 1);
            }
            //保存用户关注过的专题
//            $this->redis->hset($userFollowSp, $followSper, $data['id']);
        } elseif($keyExists) {
            if (!$SginUserExists) {
                $this->redis->set($followSginUser, -1);
            }
            //数据关注名入列
            if (!in_array($followName, $allName)) {
                $this->redis->lPush($followClickName, $followName);
            }
            //用户已取消关注
            if (!in_array($followUserName, $allName)) {
                $this->redis->lPush($followClickName, $followUserName);
            }
            $num = $this->redis->get($followSginUser);
            //判断用户关注(1) or 取消关注(-1)
            if ($num == 1) {
                $this->redis->decr($followName);
                $this->redis->set($followSginUser, -1);
                $whether = $this->redis->get($followSginUser);
                $clickNum = $this->redis->get($followName);
                //取消关注删除专题
//                $this->redis->hDel($userFollowSp, $followSper);
                //删除关注的头像
                $this->redis->lRem($followImgName, $followUserImgName, 1);
                $this->redis->lRem($followUserImgName, $data['img'], 1);
                //保存关注过的文章
                $this->redis->hSet($foUserSave, $followUserName , $whether);
                //返回关注过的人头
                $userImg = $this->getFollowImg($data['id']);
                return ['whether' => $whether, 'clickNum' => $clickNum, 'user_img' => $userImg];
            } elseif ($num == -1) {
                $init = $this->redis->get($followName);
                if (!$init) {
                    $this->redis->set($followName, 1);
                } else {
                    $this->redis->incr($followName);
                }
                $this->redis->set($followSginUser, 1);
            }
        }
        //保存用户头像
        $this->redis->lPush($followImgName, $followUserImgName);
        $this->redis->lPush($followUserImgName, $data['img']);

        //保存用户关注过的专题
        $this->redis->hset($userFollowSp, $followSper, $data['id']);
        $this->redis->expireAt($followClickName, time()+$this->config->cacheTime);
        //保存信息加入集合
        $this->redis->sAdd($setName, $data['id']);
        $this->redis->sAdd($queueSetName, $setName);//保存集合信息
        $whether = $this->redis->get($followSginUser);
        $clickNum = $this->redis->get($followName);
        //保存关注过的文章
        $this->redis->hSet($foUserSave, $followUserName , $whether);
        //返回关注过的人头
        $userImg = $this->getFollowImg($data['id']);
        return ['whether' => $whether, 'clickNum' => $clickNum, 'user_img' => $userImg];
    }

    /**
     *  获取关注量
     *  @param int $id 心情id
     */
    public function getFollow($id)
    {
        $followName = $this->config->followName.$id;
        $clickNum = $this->redis->get($followName);
        if (!$clickNum) {
            $click = Db::table('article')->field('click')->where('id', $id)->find();
            if ($click) {
                $clickNum = $click['click'];
                $this->redis->set($followName, $clickNum);
            }
        }
        return $clickNum;
    }

    //判断用户是否已经关注
    public function isFollow($id, $userId)
    {
        $followSginUser = $this->config->followSginUser.$id.$userId.":";
        $SginUserExists = $this->redis->exists($followSginUser);

        if ($SginUserExists) {
            $sgin = $this->redis->get($followSginUser);
        } else {
            $data['id'] = $id;
            $data['user_id'] = $userId;
            $signUser = $this->sginUserFollow($data);
            if ($signUser) {
                $sgin = $signUser['whether'];
            } else {
                $sgin = -1;
            }
        }
        return $sgin;
    }

    //获取用户对专题点赞标识
    public function sginUserFollow($data)
    {
        $map['table_id'] = $data['id'];
        $map['user_id'] = $data['user_id'];
        $map['table'] = 'special';
        //用户对该文章是否点赞标识
        return  Db::table('click_follow')->field('whether')->where($map)->find();
    }

    /**
     *  获取关注过的专题
     *  @param int $id 心情id
     */
    public function getFollowSp($user_id)
    {
        $id = null;
        $userFollowSp = $this->config->userFollowSp.$user_id;
        $data =  $this->redis->hGetAll($userFollowSp);
        $reverArr = array_reverse($data);
        if ($reverArr) {
            foreach ($reverArr as $k => $v) {
                $followSginUser = $this->config->followSginUser.$v.$user_id.":";
                $a = $this->redis->get($followSginUser);
                if ($a == 1) {
                    $id[] = $v;
                }
            }
            if ($id) {
                return $id;
            } else {
                return false;
            }
        }
        if (!$reverArr) {
            $map['status'] = 3;
            $map['table'] = 'special';
            $map['whether'] = 1;
            $map['user_id'] = $user_id;
            $msg = Db::table('click_follow')->field('id, table_id')->where($map)->group('table_id')->order('id desc')->select();
            foreach ($msg as $v) {
                $id[]  = $v['table_id'];
            }
        }
        if ($id) {
            return $id;
        } else {
            return false;
        }
    }

    /**
     *  获取点赞过的文章
     *  @param int $id 心情id
     */
    public function getClickAtr($user_id)
    {
        $id = null;
        $userClickAtr = $this->config->userClickAtr.$user_id;
        $data =  $this->redis->hGetAll($userClickAtr);
        if ($data) {
            foreach ($data as $k => $v) {
                $clickSginUser = $this->config->clickSginUser.$v.$user_id.":";
                $a = $this->redis->get($clickSginUser);
                if ($a == 1) {
                    $id[] = $v;
                }
            }
            if ($id) {
                return array_reverse($id);
            } else {
                return false;
            }
        }
        //缓存没数据则查询数据库中数据
        if (!$data) {
            $map['status'] = 2;
            $map['table'] = 'article';
            $map['whether'] = 1;
            $map['user_id'] = $user_id;
            $msg = Db::table('click_follow')->field('id, table_id')->where($map)->group('table_id')->order('id desc')->select();
            foreach ($msg as $v) {
                $id[]  = $v['table_id'];
            }
            if ($id) {
                return $id;
            } else {
                return false;
            }
        }
    }

    /**
     *  获取关注专题的头像
     *  @param int $id 心情id
     */
    public function getFollowImg($id)
    {
        $followImgName = $this->config->followImgListName.$id;
        $data =  $this->redis->lRange($followImgName, 0, 2);
        if (!$data) {
            return false;
        }
        foreach($data as $v) {
            $msg =  $this->redis->lRange($v, 0, 2);
            $arr[] = $msg[0];
        }
        if (!$arr) {
            return false;
        } else {
            return $arr;
        }
    }

    //获取用户对文章点赞标识
    public function addView($data)
    {
        //文章浏览量HASH键名
        $viewListName = $this->config->viewListName.$data['id'];
        //浏览量键名
        $viewName = $this->config->viewName.$data['id'];
        //总HASH表名
        $queueActName = $this->config->viewTotalName;
        //用户浏览过哪些文章队列名
        $userViewName = $this->config->userViewName.$data['user_id'];
        //集合名
        $setName = $this->config->viewQuenName.$this->config->clickTime.":";
        //总集合
        $queueViewName = $this->config->viewQuenJh;
        $keyExists = $this->redis->exists($viewName);
        if (!$keyExists) {
            //获取现有数据,加入缓存
            $arr = Db::query("select `view` from article where id = ? LIMIT 1",[$data['id']]);
            $records = !empty($arr) ? $arr[0]['view']+1 : 1;
            $this->redis->set($viewName, $records);
        } elseif($keyExists) {
            $this->redis->incr($viewName);
        }
        $this->redis->expireAt($userViewName, time()+$this->config->viewTime);
        //用户保存到文章队列中
        $this->redis->lPush($queueActName ,$viewName.':'.$data['user_id']);
        //用户浏览过文章统计存入队列中
        $this->redis->lPush($userViewName, $data['id']);
        //浏览量加入集合
        $this->redis->sAdd($setName, $data['id']);
        $this->redis->sAdd($queueViewName, $setName);//保存集合信息
        return true;
    }

    /*
     *  获取文章浏览量
     */
    public function getView($id)
    {
        $viewName = $this->config->viewName.$id;
        return $this->redis->get($viewName);
    }

    /*
     *  获取浏览过的文章
     *  @param Int $user_id 用户id
     *  return Int $id 文章id
     */
    public function getViewArt($user_id)
    {
        $id = null;
        //获取最近文章
        $userViewName = $this->config->userViewName.$user_id;
        $data = $this->redis->lRange($userViewName, 0, -1);
        //缓存没有数据则查询数据库
        if (!$data) {
            $map['status'] = 1;
            $map['table'] = 'article';
            $map['user_id'] = $user_id;
            $msg = Db::table('click_follow')->field('table_id')->where($map)->group('table_id')->select();
            foreach ($msg as $v) {
                $id[]  = $v['table_id'];
            }
        } else {
            $id[] = $this->redis->lRange($userViewName, 0, -1);
            $id = $id[0];
        }
        return $id;
    }

    /*
     *  用户浏览过的文章写入数据库
     */
    public function insertView()
    {
        $queueActName = $this->config->viewTotalName;
        $arr = $this->redis->lRange($queueActName, 0, -1);
        $actArr = array_unique($arr);
        if (!$actArr) {
            return false;
        }
        $data = [];
        foreach ($actArr as $k => $v) {
            $str = substr($v, 10);
            $r = strrpos($str, ':');
            $data[$k]['table_id'] = substr($str, 0, $r);
            $data[$k]['user_id'] = substr($str, $r+1);
        }
        $msg = null;
        foreach ($data as $v) {
            $v['table'] = 'article';
            $v['status'] = 1;
            $msg = $this->FollowModel->insert($v);
        }
        return $msg;
    }

    /*
     *  用户点过赞的文章写入数据库
     */
    public function insertClick()
    {
        //保存点过赞的文章
        $clUserSave = $this->config->clUserSave;
        $arr =  $this->redis->HGETALL($clUserSave);
        $actArr = array_reverse($arr);
        if (!$actArr) {
            return false;
        }
        $data = [];
        foreach ($actArr as $k => $v) {
            $str = substr($k, 16);
            $r = strrpos($str, ':');
            $data[$k]['table_id'] = substr($str, 0, $r);
            $data[$k]['user_id'] = substr($str, $r+1);
            $data[$k]['whether'] = $v;
        }
        $msg = null;
        foreach ($data as $v) {
            $v['table'] = 'article';
            $v['status'] = 2;
            $msg = $this->FollowModel->insert($v);
        }
        return $msg;
    }

    /*
     *  用户关注过的专题写入数据库
     */
    public function insertFollow()
    {
        //保存关注过的专题
        $foUserSave = $this->config->foUserSave;
        $arr =  $this->redis->HGETALL($foUserSave);
        $actArr = array_reverse($arr);
        if (!$actArr) {
            return false;
        }
        $data = [];
        foreach ($actArr as $k => $v) {
            $str = substr($k, 17);
            $r = strrpos($str, ':');
            $data[$k]['table_id'] = substr($str, 0, $r);
            $data[$k]['user_id'] = substr($str, $r+1);
            $data[$k]['whether'] = $v;
        }
        $msg = null;
        foreach ($data as $v) {
            $v['table'] = 'special';
            $v['status'] = 3;
            $msg = $this->FollowModel->insert($v);
        }
        return $msg;
    }
}